﻿using Newtonsoft.Json.Linq;
using System;

using System.Collections.Generic;
using xbmc_json_async.System;
using xbmc_json_async.Utilities;

namespace xbmc_json_async.Media
{
    public class Songs : List<Song>
    {
        /// <summary>
        /// Loads from json object.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        /// <returns></returns>
        public bool LoadFromJsonObject(JObject jsonObject)
        {
            try
            {
                if (jsonObject["songs"] != null)
                {
                    foreach (JObject item in (JArray)jsonObject["songs"])
                    {
                        base.Add(Song.FromJsonObject(item));
                    }

                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
    
    public class Song :  xbmc_json_async.Types.Audio.Details.Song
    {
       
        /// <summary>
        /// Initializes a new instance of the <see cref="Song"/> class.
        /// </summary>
        public Song() { }

        public Song(int id, string file, string label, string thumbnail, string artist, string title, string genre, string album, int year, float rating)
        {
            throw new NotImplementedException("Use empty ctor then call FromJsonObject");
        }

        public static Song FromJsonObject(JObject item)
        {
            var song = new Song();

            Injector injector = new Injector();
            var vObj = (object)song;
            song = (Song)injector.FillObject(vObj, (object)item);
       
            return song;
        }

        public override string ToString()
        {
            return label;
        }
    }
}